package com.shide.businessuser.UI;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.shide.businessuser.R;
import com.shide.businessuser.Utils.MessageEvent;
import com.shide.businessuser.http.entity.BrokerEntity;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/*最底下增加了一个动态添加数据的按钮;自定义布局需要从确定键回传数据*/

public class CustomOptionPickerUtil_broker {
    Context context;

    private OptionsPickerView pvCustomOptions;
    private List<BrokerEntity> mbrokers;


    public CustomOptionPickerUtil_broker(Context context, List<BrokerEntity> mbrokers) {
        this.context = context;
        this.mbrokers = mbrokers;
    }

    public OptionsPickerView initCustomOption(final TextView tv_display , TextView tv_value) {

        pvCustomOptions = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置,接收数据;
                String tx =mbrokers.get(options1).getPickerViewText();
                //String tx = rolls.get(options1).getPickerViewText(); //这里只有一级

                tv_display.setText(tx);
                tv_value.setText(mbrokers.get(options1).getBrokerId());


                MessageEvent messageEvent = new MessageEvent();
                messageEvent.setCode(MessageEvent.RECORD_REFRESH);
                EventBus.getDefault().post(messageEvent);


                //数据往哪传;
            }
        })       .setLayoutRes(R.layout.pickerview_custom_options, new CustomListener() {//自定义
            @Override
            public void customLayout(View v) {
                final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                ImageView ivCancel = (ImageView) v.findViewById(R.id.iv_cancel);
                tvSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvCustomOptions.returnData();//点击确定返回选择的数据
                        pvCustomOptions.dismiss();
                    }
                });

                ivCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvCustomOptions.dismiss();
                    }
                });

            }
        })
                .isRestoreItem(true)//切换时是否还原，设置默认选中第一项。
                .setSelectOptions(0)//设置默认选项;
                .setCyclic(false,false,false)//设置是否可以循环;
                .isDialog(false)//设置是否在页面中心弹出对话框;
                .setContentTextSize(20)//设置滚轮文字大小
                .setLineSpacingMultiplier(2.5f)//设置行间距
                .setTextColorCenter(context.getResources().getColor(R.color.blue))//选中的字体的颜色;
                .setDividerColor(context.getResources().getColor(R.color.blue))//设置分割线的颜色
                .build();
        pvCustomOptions.setPicker(mbrokers);//添加数据
        return pvCustomOptions;
    }



    
}
